home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8198 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  81 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Scope/longevity of class statics
  5. Date: Thu, 15 Feb 1996 17:41:11 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4fvr6l$m1l@news.halcyon.com>
  8. References: <4fu0qc$1h0@news.dcccd.edu>
  9. NNTP-Posting-Host: blv-pm10-ip5.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. bcalbridge@dcccd.edu (Bob Calbridge) wrote:
  13.  
  14. >I know this sounds odd but since things didn't seem to work as
  15. >expected I'll put the question to the newsgroup.  I have some
  16. >class static data that represents an upper left corner offset
  17. >for all display data.  In order to set the value I applied it
  18. >to a temporary class object inside a function.  It seemed to
  19. >work find for my purposes.  However, when I moved the code that
  20. >set the values to another function that was invoked prior to the
  21. >original function where it was instigated the values ended up
  22. >improperly set by the time I got to my main code.  
  23.  
  24. >Does class static data only have scope where the object that
  25. >was used to set it has scope?  This doesn't sound right to me
  26. >but it seems as if that's the way it's behaving.
  27. >-- 
  28. >=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. >- Bob Calbridge = Dallas County Community College District  - 
  30. >= bcalbridge@dcccd.edu               PC Systems Programmer  =
  31. >- Postmaster                                                -
  32. >=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. >     Patience is a virtue.  It's not a job requirement.
  34.  
  35. If I understand you, you had code like 
  36.  
  37. class CMyDataView
  38. {
  39.     ...
  40.     public:
  41.     static int s_xorigin;
  42.     static int s_yorigin;
  43. };
  44.  
  45. int CMyDataView::s_xorigin;
  46. int CMyDataView::s_yorigin;
  47.  
  48. void draw()
  49. {
  50.     CMyDataView   myView;
  51.     myView.s_xorigin = 10;        // This worked
  52.     myView.s_yorigin. = 20;
  53.     ...
  54. }
  55.  
  56. then you moved the initialization code to 
  57.  
  58. void init()
  59. {
  60.     CMyDataView   myView;
  61.     myView.s_xorigin = 10;        
  62.     myView.s_yorigin. = 20;    
  63.     // or maybe CMyDataView::s_xorigin = 10; etc.
  64. }
  65.  
  66. void main()
  67. {
  68.     init();
  69.     draw();
  70. }
  71.  
  72. and you find that it failed?
  73.  
  74. Static data has global scope; this should have succeeded.   Is there
  75. anything more complex going on here?  Marshalling over OLE?  Sharing
  76. the CMyDataView DLL among multple processes and hoping the static
  77. variable memory is also shared?  
  78.  
  79.                             --Norm 
  80.  
  81.